package top.college.jjb;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import top.college.dao.JDBC_ConnClose;
import top.college.dao.JDBC_SQL;

import TOP_Version1.Top_JDBC_Connection;

// 학생정보등록
public class studencreatre extends JPanel {
	private JTextField t1;
	private JTextField t2;
	private JTextField t3;
	private JTextField t4;
	private JTextField t;
	private static Connection conn;
	private static PreparedStatement pstmt;
	private static ResultSet rs;
	private JTextField t5;
	
	
	public studencreatre() {
		pn1();
		pn2();
		pn3();
	
	}
	

private void pn1(){
	setLayout(new BorderLayout(0, 0));
	JPanel infop = new JPanel();
	add(infop, BorderLayout.NORTH);
	
	JLabel infolab = new JLabel("학생 정보 등록");
	infop.add(infolab);
}
private void pn2(){
	JPanel panel = new JPanel();
	add(panel, BorderLayout.CENTER);
	panel.setLayout(new BorderLayout(0, 0));
	
	JPanel panel_1 = new JPanel();
	panel.add(panel_1, BorderLayout.WEST);
	panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.PAGE_AXIS));
	
	JLabel lblNewLabel_1 = new JLabel("학번");
	lblNewLabel_1.setAlignmentY(Component.BOTTOM_ALIGNMENT);
	panel_1.add(lblNewLabel_1);
	
	JLabel lblNewLabel = new JLabel("패스워드");
	lblNewLabel.setAlignmentY(Component.BOTTOM_ALIGNMENT);
	panel_1.add(lblNewLabel);
	
	JLabel lblNewLabel_2 = new JLabel("이름");
	lblNewLabel_2.setAlignmentY(Component.BOTTOM_ALIGNMENT);
	panel_1.add(lblNewLabel_2);
	
	JLabel lblNewLabel_3 = new JLabel("전화번호");
	panel_1.add(lblNewLabel_3);
	
	JLabel lblNewLabel_4 = new JLabel("주소");
	panel_1.add(lblNewLabel_4);
	
	JLabel gkrr = new JLabel("학과번호");
	panel_1.add(gkrr);

	JPanel panel2 = new JPanel();
	panel.add(panel2, BorderLayout.CENTER);
	panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
	
	
	t = new JTextField();
	panel2.add(t);
	t.setColumns(10);
	
	t1 = new JTextField();
	panel2.add(t1);
	t1.setColumns(10);
	
	t2 = new JTextField();
	panel2.add(t2);
	t2.setColumns(10);
	
	t3 = new JTextField();
	panel2.add(t3);
	t3.setColumns(10);
	
	t4 = new JTextField();
	panel2.add(t4);
	t4.setColumns(10);
	
	t5 = new JTextField();
	panel2.add(t5);
	t5.setColumns(10);
	
	
}

private void pn3(){
	JPanel panel_2 = new JPanel();
	panel_2.setPreferredSize(new Dimension(200, 10));
	add(panel_2, BorderLayout.EAST);
	
	JPanel panel_3 = new JPanel();
	panel_3.setPreferredSize(new Dimension(10, 50));
	add(panel_3, BorderLayout.SOUTH);
	panel_3.setLayout(new BorderLayout(0, 0));
	
	JPanel panel_5 = new JPanel();
	panel_3.add(panel_5, BorderLayout.CENTER);
	
	JButton btnNewButton_1 = new JButton("등록");
	btnNewButton_1.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
			StudentVO sv = new  StudentVO();
			sv.setStd_no(t.getText());
			sv.setStd_name(t1.getText());
			sv.setStd_pw(t2.getText());
			sv.setStd_tel(t3.getText());
			sv.setStd_addr(t4.getText());
			sv.setDept_no(t5.getText());
			
			try {
				conn = JDBC_ConnClose.openDataBase();
				pstmt = conn.prepareStatement(JDBC_SQL_1.StudentInsertSQL);
				pstmt.setString( 1, sv.getStd_no());
				pstmt.setString( 2, sv.getStd_pw());
				pstmt.setString( 3, sv.getStd_name());
				pstmt.setString( 4, sv.getStd_tel());
				pstmt.setString( 5, sv.getStd_addr());
				pstmt.setString( 6, sv.getDept_no());
				pstmt.executeUpdate();
				System.out.println("입력이 완료되었습니다.");
			} catch ( Exception ex ) {
				ex.printStackTrace();
			} finally {
				Top_JDBC_Connection.closeDataBase(conn, pstmt, rs);
			}
			
			
			
			/*if(sss.createstudent(sv))
				JOptionPane.showMessageDialog(null, "입력완료");
			*/
		}
	});
	panel_5.add(btnNewButton_1);
	
	JButton btnNewButton = new JButton("확인");
	panel_5.add(btnNewButton);

}


}

	
